﻿using FarmSmartSleep.Common.Domain.PM;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Common.Infrastructure;
using MediatR;

namespace FarmSmartSleep.Organ.API.Application.ProductionManagement.LambWeaningCommands
{
    public class LambWeaningCreateHandler : IRequestHandler<LambWeaningCreateCommand, Result>
    {
        private readonly IBaseRepository<LambWeaning> lambRep;

        public LambWeaningCreateHandler(IBaseRepository<LambWeaning> lambRep)
        {
            this.lambRep = lambRep;
        }


        /// <summary>
        /// 羔羊断奶添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<Result> Handle(LambWeaningCreateCommand request, CancellationToken cancellationToken)
        {
            var quest = new Result() { Code = (int)CodeEnum.success };

            var res = await lambRep.AddRange(request.lambWeanings);

            quest.Code = 1;
            quest.Data = res;

            return quest;
        }
    }
}
